<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">

  <script>
    (function(){
        if(''){
            if (prompt('请输入文章密码') !== ''){
                alert('密码错误！');
                history.back();
            }
        }
    })();
  </script>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.3" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/favicon.ico?v=5.1.3">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon.ico?v=5.1.3">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon.ico?v=5.1.3">


  <link rel="mask-icon" href="/images/favicon.ico?v=5.1.3" color="#222">





  <meta name="keywords" content="Python,face_recognition中文文档," />










<meta name="description" content="Face Recognition人脸识别库这是世界上最简单的人脸识别库了。你可以通过Python引用或者命令行的形式使用它，来管理和识别人脸。该软件包使用dlib中最先进的人脸识别深度学习算法，使得识别准确率在《Labled Faces in the world》测试基准下达到了99.38%。它同时提供了一个叫face_recognition的命令行工具，以便你可以用命令行对一个文件夹中的图片进行">
<meta name="keywords" content="Python,face_recognition中文文档">
<meta property="og:type" content="article">
<meta property="og:title" content="[face_recognition中文文档] 第1节 人脸识别">
<meta property="og:url" content="http://www.kangvcar.com/face-recognition中文文档-第1节-人脸识别/index.html">
<meta property="og:site_name" content="Kangvcar | Blogs">
<meta property="og:description" content="Face Recognition人脸识别库这是世界上最简单的人脸识别库了。你可以通过Python引用或者命令行的形式使用它，来管理和识别人脸。该软件包使用dlib中最先进的人脸识别深度学习算法，使得识别准确率在《Labled Faces in the world》测试基准下达到了99.38%。它同时提供了一个叫face_recognition的命令行工具，以便你可以用命令行对一个文件夹中的图片进行">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/2640591-feccdb7521c773cd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/2640591-ba41d9baeb1bd4f1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/2640591-9cebf7989905cdbf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/2640591-a50a601146624c98.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/2640591-988581b251acb5a7.gif?imageMogr2/auto-orient/strip">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/2640591-7c754e41e224f0bf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/2640591-1553f10adc1fc607.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:updated_time" content="2017-11-14T11:54:57.425Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="[face_recognition中文文档] 第1节 人脸识别">
<meta name="twitter:description" content="Face Recognition人脸识别库这是世界上最简单的人脸识别库了。你可以通过Python引用或者命令行的形式使用它，来管理和识别人脸。该软件包使用dlib中最先进的人脸识别深度学习算法，使得识别准确率在《Labled Faces in the world》测试基准下达到了99.38%。它同时提供了一个叫face_recognition的命令行工具，以便你可以用命令行对一个文件夹中的图片进行">
<meta name="twitter:image" content="http://upload-images.jianshu.io/upload_images/2640591-feccdb7521c773cd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.3',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://www.kangvcar.com/face-recognition中文文档-第1节-人脸识别/"/>



  <script>
  (function(i,s,o,g,r,a,m){i["DaoVoiceObject"]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;a.charset="utf-8";m.parentNode.insertBefore(a,m)})(window,document,"script",('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/0f81ff2f.js","daovoice")
  daovoice('init', {
      app_id: "f8921861"
    });
  daovoice('update');
  </script>





  <title>[face_recognition中文文档] 第1节 人脸识别 | Kangvcar | Blogs</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
      <a href="https://github.com/kangvcar/kangvcar.github.io" class="github-corner" aria-label="View source on Github"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#FD6C6C; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
<!--       <a href="https://github.com/kangvcar/kangvcar.github.io"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/365986a132ccd6a44c23a9169022c0b5c890c387/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f7265645f6161303030302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png"></a>
 -->
    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Kangvcar | Blogs</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">知识的广度是深度的副产品</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.kangvcar.com/face-recognition中文文档-第1节-人脸识别/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Kangvcar">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/uploads/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Kangvcar | Blogs">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">[face_recognition中文文档] 第1节 人脸识别</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-11-15T03:49:52+08:00">
                2017-11-14
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/face-recognition/" itemprop="url" rel="index">
                    <span itemprop="name">face_recognition</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/face-recognition中文文档-第1节-人脸识别/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="face-recognition中文文档-第1节-人脸识别/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  2,414
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  10
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="Face-Recognition人脸识别库"><a href="#Face-Recognition人脸识别库" class="headerlink" title="Face Recognition人脸识别库"></a>Face Recognition人脸识别库</h1><p>这是世界上最简单的人脸识别库了。你可以通过Python引用或者命令行的形式使用它，来管理和识别人脸。<br>该软件包使用dlib中最先进的人脸识别深度学习算法，使得识别准确率在《Labled Faces in the world》测试基准下达到了99.38%。<br>它同时提供了一个叫face_recognition的命令行工具，以便你可以用命令行对一个文件夹中的图片进行识别操作。</p>
<h2 id="特征"><a href="#特征" class="headerlink" title="特征"></a>特征</h2><h3 id="在图片中识别人脸"><a href="#在图片中识别人脸" class="headerlink" title="在图片中识别人脸"></a>在图片中识别人脸</h3><p>找到图片中所有的人脸：</p>
<p><img src="http://upload-images.jianshu.io/upload_images/2640591-feccdb7521c773cd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="示例图1"></p>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">import face_recognition</span><br><span class="line">image=face_recognition.load_image_file(<span class="string">"your_file.jpg"</span>)</span><br><span class="line">face_locations=face_recognition.face_locations(image)</span><br></pre></td></tr></table></figure>
<h3 id="找到并操作图片中的脸部特征"><a href="#找到并操作图片中的脸部特征" class="headerlink" title="找到并操作图片中的脸部特征"></a>找到并操作图片中的脸部特征</h3><p>获得图片中人类眼睛、鼻子、嘴、下巴的位置和轮廓：</p>
<p><img src="http://upload-images.jianshu.io/upload_images/2640591-ba41d9baeb1bd4f1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="示例图2"></p>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">import face_recognition</span><br><span class="line">image = face_recognition.load_image_file(<span class="string">"your_file.jpg"</span>)</span><br><span class="line">face_landmarks_list = face_recognition.face_landmarks(image)</span><br></pre></td></tr></table></figure>
<p>找到脸部特征有很多超级有用的应用场景，当然你也可以把它用在最显而易见的功能上：美颜功能 <a href="https://github.com/ageitgey/face_recognition/blob/master/examples/digital_makeup.py" target="_blank" rel="external">就像美图秀秀那样</a>：</p>
<p><img src="http://upload-images.jianshu.io/upload_images/2640591-9cebf7989905cdbf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="示例图3"></p>
<h3 id="鉴定图片中的脸"><a href="#鉴定图片中的脸" class="headerlink" title="鉴定图片中的脸"></a>鉴定图片中的脸</h3><p>识别图片中的人是谁</p>
<p><img src="http://upload-images.jianshu.io/upload_images/2640591-a50a601146624c98.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="示例图4"></p>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">import face_recognition</span><br><span class="line">known_image=face_recognition.load_image_file(<span class="string">"biden.jpg"</span>)</span><br><span class="line">unknown_image=face_recognition.load_image_file(<span class="string">"unknown.jpg"</span>)</span><br><span class="line">biden_encoding=face_recognition.face_encodings(known_image)[0</span><br><span class="line">]unknown_encoding=face_recognition.face_encodings(unknown_image)[0]</span><br><span class="line">results=face_recognition.compare_faces([biden_encoding],unknown_encoding)</span><br></pre></td></tr></table></figure>
<p>你甚至可以用这个软件包做人脸的实时识别：</p>
<p><img src="http://upload-images.jianshu.io/upload_images/2640591-988581b251acb5a7.gif?imageMogr2/auto-orient/strip" alt="示例图5"></p>
<p>这里有一个<a href="https://github.com/ageitgey/face_recognition/blob/master/examples/facerec_from_webcam_faster.py" target="_blank" rel="external">实时识别的例子</a></p>
<h2 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h2><h3 id="环境要求"><a href="#环境要求" class="headerlink" title="环境要求:"></a>环境要求:</h3><ul>
<li>Python3.3+或者Python2.7</li>
<li>MacOS或者Linux（Windows不做支持，但是你可以试试，也许也能运行）</li>
</ul>
<h3 id="安装步骤"><a href="#安装步骤" class="headerlink" title="安装步骤"></a>安装步骤</h3><h4 id="在Mac或Linux上安装"><a href="#在Mac或Linux上安装" class="headerlink" title="在Mac或Linux上安装"></a>在Mac或Linux上安装</h4><p>首先，确保你安装了dlib，以及该软件的Python绑定接口。如果没有的话，看这篇安装说明：</p>
<ul>
<li><a href="https://gist.github.com/ageitgey/629d75c1baac34dfa5ca2a1928a7aeaf" target="_blank" rel="external">如何从macOS或Ubuntu上安装dlib</a></li>
</ul>
<p>然后，使用<code>pip3</code>（Python 2的<code>pip2</code>）从pypi安装此模块：</p>
<figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pip3 <span class="keyword">install</span> face_recognition</span><br></pre></td></tr></table></figure>
<p>如果你安装遇到问题，可以试试这个安装好了的<a href="https://medium.com/@ageitgey/try-deep-learning-in-python-now-with-a-fully-pre-configured-vm-1d97d4c3e9b" target="_blank" rel="external">虚拟机</a></p>
<h4 id="在树莓派2-上安装"><a href="#在树莓派2-上安装" class="headerlink" title="在树莓派2+上安装"></a>在树莓派2+上安装</h4><ul>
<li><a href="https://gist.github.com/ageitgey/1ac8dbe8572f3f533df6269dab35df65" target="_blank" rel="external">在树莓派2+上安装说明</a></li>
</ul>
<h4 id="在Windows上安装"><a href="#在Windows上安装" class="headerlink" title="在Windows上安装"></a>在Windows上安装</h4><p>虽然Windows不是官方支持的，但是有热心网友写出了一个Windows上的使用指南，请看这里：</p>
<ul>
<li><a href="https://github.com/ageitgey/face_recognition/issues/175#issue-257710508" target="_blank" rel="external">@ masoudr的Windows 10安装指南（dlib + face_recognition）</a></li>
</ul>
<h4 id="使用已经配置好的虚拟机（支持VMWare和VirtualBox）"><a href="#使用已经配置好的虚拟机（支持VMWare和VirtualBox）" class="headerlink" title="使用已经配置好的虚拟机（支持VMWare和VirtualBox）"></a>使用已经配置好的虚拟机（支持VMWare和VirtualBox）</h4><ul>
<li><a href="https://medium.com/@ageitgey/try-deep-learning-in-python-now-with-a-fully-pre-configured-vm-1d97d4c3e9b" target="_blank" rel="external">下载预配置的虚拟机映像</a>（适用于VMware Player或VirtualBox）。</li>
</ul>
<h2 id="使用方法"><a href="#使用方法" class="headerlink" title="使用方法"></a>使用方法</h2><h3 id="命令行界面"><a href="#命令行界面" class="headerlink" title="命令行界面"></a>命令行界面</h3><p>如果你已经安装了face_recognition，那么你的系统中已经有了一个名为face_recognition的命令，你可以使用它对图片进行识别，或者对一个文件夹中的所有图片进行识别。<br>首先你需要提供一个文件夹，里面是所有你希望系统认识的人的图片。其中每个人一张图片，图片以人的名字命名：</p>
<p><img src="http://upload-images.jianshu.io/upload_images/2640591-7c754e41e224f0bf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="示例图6"></p>
<p>接下来，你需要准备另一个文件夹，里面是你要识别的图片：</p>
<p><img src="http://upload-images.jianshu.io/upload_images/2640591-1553f10adc1fc607.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="示例图7"></p>
<p>然后你就可以运行face_recognition命令了，把刚刚准备的两个文件夹作为参数传入，命令就会返回需要识别的图片中都出现了谁：</p>
<figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ face_recognition .<span class="regexp">/pictures_of_people_i_know/</span> .<span class="regexp">/unknown_pictures/</span></span><br><span class="line"></span><br><span class="line"><span class="regexp">/unknown_pictures/u</span>nknown.jpg,Barack Obama</span><br><span class="line"><span class="regexp">/face_recognition_test/u</span>nknown_pictures<span class="regexp">/unknown.jpg,unknown_person</span></span><br></pre></td></tr></table></figure>
<p>输出中，识别到的每张脸都单独占一行，输出格式为&lt;图片名称&gt;,&lt;人名&gt;。<br>unknown_person 是一个与你的文件夹的已知人图像不匹配的人物。</p>
<h3 id="调整公差-灵敏度"><a href="#调整公差-灵敏度" class="headerlink" title="调整公差/灵敏度"></a>调整公差/灵敏度</h3><p>如果你正在为同一个人获得多个比较，那可能就是这样您的照片中的人看起来非常相似，容差值较低需要使脸部比较更严格。<br>你可以用<code>--tolerance</code>参数来做到这一点。默认容差值为0.6，较低的数字使脸部比较更严格：</p>
<figure class="highlight jboss-cli"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ face_recognition <span class="params">--tolerance</span> 0.54 <span class="string">./pictures_of_people_i_know/</span> <span class="string">./unknown_pictures/</span></span><br><span class="line"></span><br><span class="line"><span class="string">/unknown_pictures/unknown.jpg</span>,Barack Obama</span><br><span class="line"><span class="string">/face_recognition_test/unknown_pictures/unknown.jpg</span>,unknown_person</span><br></pre></td></tr></table></figure>
<p>如果要按顺序查看每次计算出的面距要调整公差设置，可以使用：<code>--show-distancetrue</code></p>
<figure class="highlight jboss-cli"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ face_recognition <span class="params">--show-distance</span> <span class="literal">true</span> <span class="string">./pictures_of_people_i_know/</span> <span class="string">./unknown_pictures/</span></span><br><span class="line"></span><br><span class="line"><span class="string">/unknown_pictures/unknown.jpg</span>,Barack Obama,0.378542298956785</span><br><span class="line"><span class="string">/face_recognition_test/unknown_pictures/unknown.jpg</span>,unknown_person,None</span><br></pre></td></tr></table></figure>
<h3 id="更多例子"><a href="#更多例子" class="headerlink" title="更多例子"></a>更多例子</h3><p>如果你只想知道每张照片中的人的名字，但不要关心文件名，你可以这样做：</p>
<figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ face_recognition .<span class="regexp">/pictures_of_people_i_know/</span> .<span class="regexp">/unknown_pictures/</span> | cut -d <span class="string">','</span> -f2</span><br><span class="line"></span><br><span class="line">Barack Obama</span><br><span class="line">unknown_person</span><br></pre></td></tr></table></figure>
<h3 id="加快人脸识别"><a href="#加快人脸识别" class="headerlink" title="加快人脸识别"></a>加快人脸识别</h3><p>如果您有多个CPU内核的电脑，则可以并行完成脸部识别。例如，如果您的系统有4个CPU内核，您可以通过使用在相同的时间量内所有的CPU内核并行处理约4倍的图像。<br>如果您使用的是Python 3.4或更新版本，请传入参数：<code>--cpus &lt;number_of_cpu_cores_to_use&gt; parameter</code>:</p>
<figure class="highlight jboss-cli"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ face_recognition <span class="params">--cpus</span> 4 <span class="string">./pictures_of_people_i_know/</span> <span class="string">./unknown_pictures/</span></span><br></pre></td></tr></table></figure>
<p>您还可以传入使用系统中的所有CPU内核。–cpus-1</p>
<h3 id="Python模块"><a href="#Python模块" class="headerlink" title="Python模块"></a>Python模块</h3><p>你可以通过导入face_recognition模块来使用它，使用方式超级简单，文档在这里<a href="https://face-recognition.readthedocs.io/en/latest/face_recognition.html" target="_blank" rel="external">API文件</a>：</p>
<h3 id="自动找到图片中所有的脸"><a href="#自动找到图片中所有的脸" class="headerlink" title="自动找到图片中所有的脸"></a>自动找到图片中所有的脸</h3><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">import face_recognition</span><br><span class="line"></span><br><span class="line">image = face_recognition.load_image_file(<span class="string">"my_picture.jpg"</span>)</span><br><span class="line">face_locations = face_recognition.face_locations(image)</span><br><span class="line"></span><br><span class="line"><span class="comment"># face_locations is now an array listing the co-ordinates of each face!</span></span><br></pre></td></tr></table></figure>
<p>看看<a href="https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_picture.py" target="_blank" rel="external">这个例子</a>自己实践一下，试试看。</p>
<p>你还可以自定义替换人类识别的深度学习模型。</p>
<p>注意：想获得比较好的性能的话，你可能需要GPU加速（使用英伟达的CUDA库）。所以编译的时候你也需要开启dlib的GPU加速选项。</p>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">import face_recognition</span><br><span class="line"></span><br><span class="line">image = face_recognition.load_image_file(<span class="string">"my_picture.jpg"</span>)</span><br><span class="line">face_locations = face_recognition.face_locations(image, model=<span class="string">"cnn"</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># face_locations is now an array listing the co-ordinates of each face!</span></span><br></pre></td></tr></table></figure>
<p>你也可以通过<a href="https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_picture_cnn.py" target="_blank" rel="external">这个例子</a>实践一下，试试看。</p>
<p>如果你有很多图片和GPU，你也可以并行快速识别，看<a href="https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_batches.py" target="_blank" rel="external">这篇文章</a>。</p>
<h3 id="自动识别人脸特征"><a href="#自动识别人脸特征" class="headerlink" title="自动识别人脸特征"></a>自动识别人脸特征</h3><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">import face_recognition</span><br><span class="line"></span><br><span class="line">image = face_recognition.load_image_file(<span class="string">"my_picture.jpg"</span>)</span><br><span class="line">face_landmarks_list = face_recognition.face_landmarks(image)</span><br><span class="line"></span><br><span class="line"><span class="comment"># face_landmarks_list is now an array with the locations of each facial feature in each face.</span></span><br><span class="line"><span class="comment"># face_landmarks_list[0]['left_eye'] would be the location and outline of the first person's left eye.</span></span><br></pre></td></tr></table></figure>
<p>试试<a href="https://github.com/ageitgey/face_recognition/blob/master/examples/find_facial_features_in_picture.py" target="_blank" rel="external">这个例子</a>，试试看。</p>
<h3 id="识别人脸鉴定是哪个人"><a href="#识别人脸鉴定是哪个人" class="headerlink" title="识别人脸鉴定是哪个人"></a>识别人脸鉴定是哪个人</h3><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">import face_recognition</span><br><span class="line"></span><br><span class="line">picture_of_me = face_recognition.load_image_file(<span class="string">"me.jpg"</span>)</span><br><span class="line">my_face_encoding = face_recognition.face_encodings(picture_of_me)[0]</span><br><span class="line"></span><br><span class="line"><span class="comment"># my_face_encoding now contains a universal 'encoding' of my facial features that can be compared to any other picture of a face!</span></span><br><span class="line"></span><br><span class="line">unknown_picture = face_recognition.load_image_file(<span class="string">"unknown.jpg"</span>)</span><br><span class="line">unknown_face_encoding = face_recognition.face_encodings(unknown_picture)[0]</span><br><span class="line"></span><br><span class="line"><span class="comment"># Now we can see the two face encodings are of the same person with `compare_faces`!</span></span><br><span class="line"></span><br><span class="line">results = face_recognition.compare_faces([my_face_encoding], unknown_face_encoding)</span><br><span class="line"></span><br><span class="line">if results[0] == True:</span><br><span class="line">    print(<span class="string">"It's a picture of me!"</span>)</span><br><span class="line"><span class="section">else:</span></span><br><span class="line">    print(<span class="string">"It's not a picture of me!"</span>)</span><br></pre></td></tr></table></figure>
<p>这里是一个<a href="https://github.com/ageitgey/face_recognition/blob/master/examples/recognize_faces_in_pictures.py" target="_blank" rel="external">例子</a>，试试看。</p>
<h2 id="Python代码示例"><a href="#Python代码示例" class="headerlink" title="Python代码示例"></a>Python代码示例</h2><p>所有的例子都<a href="https://github.com/ageitgey/face_recognition/tree/master/examples" target="_blank" rel="external">在这里</a>。</p>
<h3 id="人脸检测"><a href="#人脸检测" class="headerlink" title="人脸检测"></a>人脸检测</h3><ul>
<li><a href="https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_picture.py" target="_blank" rel="external">在照片中找到面孔</a></li>
<li><a href="https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_picture_cnn.py" target="_blank" rel="external">在照片中找到面孔（使用深度学习）</a></li>
<li><a href="https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_batches.py" target="_blank" rel="external">在GPU（使用深度学习）的图像批量查找面孔</a></li>
</ul>
<h3 id="面部特征"><a href="#面部特征" class="headerlink" title="面部特征"></a>面部特征</h3><ul>
<li><a href="https://github.com/ageitgey/face_recognition/blob/master/examples/find_facial_features_in_picture.py" target="_blank" rel="external">识别照片中的特定面部特征</a></li>
<li><a href="https://github.com/ageitgey/face_recognition/blob/master/examples/digital_makeup.py" target="_blank" rel="external">应用（可怕的丑陋）数字化妆</a></li>
</ul>
<h3 id="面部识别"><a href="#面部识别" class="headerlink" title="面部识别"></a>面部识别</h3><ul>
<li><a href="https://github.com/ageitgey/face_recognition/blob/master/examples/recognize_faces_in_pictures.py" target="_blank" rel="external">根据已知人的照片，查找并识别照片中的未知脸部</a></li>
<li><a href="https://github.com/ageitgey/face_recognition/blob/master/examples/face_distance.py" target="_blank" rel="external">通过数字表面距离比较面部，而不是仅True / False匹配</a></li>
<li><a href="https://github.com/ageitgey/face_recognition/blob/master/examples/facerec_from_webcam.py" target="_blank" rel="external">使用您的网络摄像头识别实况视频中的人脸 - 简单/较慢版本（需要安装OpenCV）</a></li>
<li><a href="https://github.com/ageitgey/face_recognition/blob/master/examples/facerec_from_webcam_faster.py" target="_blank" rel="external">使用您的网络摄像头识别实况视频中的人脸 - 更快的版本（需要安装OpenCV）</a></li>
<li><a href="https://github.com/ageitgey/face_recognition/blob/master/examples/facerec_from_video_file.py" target="_blank" rel="external">识别视频文件中的面孔并写出新的视频文件（需要安装OpenCV）</a></li>
<li><a href="https://github.com/ageitgey/face_recognition/blob/master/examples/facerec_on_raspberry_pi.py" target="_blank" rel="external">识别Raspberry Pi w /相机的面孔</a></li>
<li><a href="https://github.com/ageitgey/face_recognition/blob/master/examples/web_service_example.py" target="_blank" rel="external">运行Web服务通过HTTP识别面孔（需要安装Flask）</a></li>
</ul>
<h3 id="人脸识别如何运作"><a href="#人脸识别如何运作" class="headerlink" title="人脸识别如何运作"></a>人脸识别如何运作</h3><p>如果你想了解脸部位置和识别如何工作，而不是取决于黑匣子库，请<a href="https://medium.com/@ageitgey/machine-learning-is-fun-part-4-modern-face-recognition-with-deep-learning-c3cffc121d78" target="_blank" rel="external">阅读我的文章</a>。</p>
<h3 id="注意事项"><a href="#注意事项" class="headerlink" title="注意事项"></a>注意事项</h3><ul>
<li>面部识别模型是针对成年人进行培训的，对儿童的工作效果不佳。它倾向于使用默认比较阈值0.6来混合孩子很容易。</li>
</ul>
<h3 id="部署到云端主机（Heroku，AWS等）"><a href="#部署到云端主机（Heroku，AWS等）" class="headerlink" title="部署到云端主机（Heroku，AWS等）"></a>部署到云端主机（Heroku，AWS等）</h3><p>由于<code>face_recognition</code>取决于使用<code>dlib</code>C ++编写的内容，将其用于云端托管服务商，如Heroku或AWS 部署应用程序可能很棘手。<br>为了使事情更容易，这个repo中有一个Dockerfile示例，显示如何在<a href="https://www.docker.com/" target="_blank" rel="external">Docker</a>容器中运行一个构建的应用程序<code>face_recognition</code>。因此，您应该可以部署支持Docker图像的任何服务。</p>
<h3 id="常见问题"><a href="#常见问题" class="headerlink" title="常见问题"></a>常见问题</h3><p>问题：使用face_recognition或运行示例时出现 <code>Illegal instruction(coredumped)</code></p>
<p>解决方案：<code>dlib</code>使用SSE4或AVX进行编译，但您的CPU太旧，不支持。<br>您需要更改<code>dlib</code>代码后重新编译<a href="https://github.com/ageitgey/face_recognition/issues/11#issuecomment-287398611" target="_blank" rel="external">这里概述代码更改</a>。</p>
<p>问题：运行摄像头示例时出现<code>RuntimeError: Unsupported image type, must be 8bit gray or RGB image.</code></p>
<p>解决方案：您的网络摄像机可能未正确使用OpenCV设置。<a href="https://github.com/ageitgey/face_recognition/issues/21#issuecomment-287779524" target="_blank" rel="external">在这里寻找更多帮助</a>。<br>问题：运行<code>pip2 install face_recognition</code>时出现<code>MemoryError</code></p>
<p>解决方案：face_recognition_models文件对于可用的缓存内存来说太大了。尝试使用以下方法<code>pip2 --no-cache-dir install face_recognition</code>来尽量避免这个问题。</p>
<p>问题：<code>AttributeError: &#39;module&#39; object has no attribute &#39;face_recognition_model_v1&#39;</code></p>
<p>解决方案：<code>dlib</code>您安装的版本太旧了。您需要19.7或更新版本。升级<code>dlib</code>。</p>
<p>问题：<code>AttributeError: &#39;Module&#39; object has no attribute &#39;cnn_face_detection_model_v1&#39;</code></p>
<p>解决方案：<code>dlib</code>您安装的版本太旧了。您需要19.7或更新版本。升级<code>dlib</code>。</p>
<p>问题：<code>TypeError: imread() got an unexpected keyword argument &#39;mode&#39;</code></p>
<p>解决方案：<code>scipy</code>您安装的版本太旧了。您需要版本0.17或更新版本。升级<code>scipy</code>。</p>
<h3 id="谢谢"><a href="#谢谢" class="headerlink" title="谢谢"></a>谢谢</h3><ul>
<li>非常感谢<a href="https://github.com/davisking" target="_blank" rel="external">戴维斯·金</a>（<a href="https://twitter.com/nulhom" target="_blank" rel="external">@nulhom</a>）创建dlib并提供训练有素的面部特征检测和此库中使用的脸部编码模型。有关ResNet上有关面部编码的更多信息，请查看他的<a href="http://blog.dlib.net/2017/02/high-quality-face-recognition-with-deep.html" target="_blank" rel="external">博文</a>。</li>
<li>感谢所有在Python数据科学图书馆工作的所有人，如data，scipy，scikit-image，pillow等，使得这种东西在Python中如此简单而有趣。</li>
<li>感谢<a href="https://github.com/audreyr/cookiecutter" target="_blank" rel="external">Cookiecutter</a>和<a href="https://github.com/audreyr/cookiecutter-pypackage" target="_blank" rel="external">audreyr / cookiecutter-pypackage</a>项目模板，使Python项目打包方式更有效率。</li>
</ul>

      
    </div>
    
    
    


  


    

    
      <div>
        <div align="center">
 
   <div class="">
   <p>&nbsp</p>
   <p>&nbsp</p>
   <p><span>
   <b>本文地址：</b><a href="/face-recognition中文文档-第1节-人脸识别/" title="[face_recognition中文文档] 第1节 人脸识别">http://www.kangvcar.com/face-recognition中文文档-第1节-人脸识别/</a><br/><b>转载请注明出处，谢谢！</b>
   </span></p>
   </div>
 
</div>


<div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>坚持原创技术分享，随意打赏！您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.jpg" alt="Kangvcar 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.jpg" alt="Kangvcar 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <div>
      
        <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------感谢您的阅读-------------</div>
    
</div>
      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Python/" rel="tag"><i class="fa fa-tag"></i> Python</a>
          
            <a href="/tags/face-recognition中文文档/" rel="tag"><i class="fa fa-tag"></i> face_recognition中文文档</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/手把手教你用1行代码实现人脸识别-Python-Face-recognition/" rel="next" title="手把手教你用1行代码实现人脸识别 -- Python Face_recognition">
                <i class="fa fa-chevron-left"></i> 手把手教你用1行代码实现人脸识别 -- Python Face_recognition
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/face-recognition中文文档-第2节-安装/" rel="prev" title="[face_recognition中文文档] 第2节 安装">
                [face_recognition中文文档] 第2节 安装 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
        <!-- JiaThis Button BEGIN -->
<div class="jiathis_style">
<span class="jiathis_txt">分享到：</span>
<a class="jiathis_button_fav">收藏夹</a>
<a class="jiathis_button_copy">复制网址</a>
<a class="jiathis_button_email">邮件</a>
<a class="jiathis_button_weixin">微信</a>
<a class="jiathis_button_qzone">QQ空间</a>
<a class="jiathis_button_tqq">腾讯微博</a>
<a class="jiathis_button_douban">豆瓣</a>
<a class="jiathis_button_share">一键分享</a>

<a href="http://www.jiathis.com/share?uid=2140465" class="jiathis jiathis_txt jiathis_separator jtico jtico_jiathis" target="_blank">更多</a>
<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" >
var jiathis_config={
  data_track_clickback:true,
  summary:"",
  shortUrl:false,
  hideMore:false
}
</script>
<script type="text/javascript" src="http://v3.jiathis.com/code/jia.js?uid=" charset="utf-8"></script>
<!-- JiaThis Button END -->
      
    </div>
  </div>


          </div>
          


          

  
      <div id="lv-container" data-id="city" data-uid="MTAyMC8zMTgzNi84NDAw"></div>


  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/uploads/avatar.png"
                alt="Kangvcar" />
            
              <p class="site-author-name" itemprop="name">Kangvcar</p>
              <p class="site-description motion-element" itemprop="description">知识的广度是深度的副产品</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">28</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">13</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">32</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          <div class="links-of-author motion-element">
            
              
                <span class="links-of-author-item">
                  <a href="https://github.com/kangvcar" target="_blank" title="GitHub">
                    
                      <i class="fa fa-fw fa-github"></i>GitHub</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="http://cv.kangvcar.com" target="_blank" title="我的简历">
                    
                      <i class="fa fa-fw fa-user"></i>我的简历</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="https://twitter.com/kangvcar" target="_blank" title="Twitter">
                    
                      <i class="fa fa-fw fa-twitter"></i>Twitter</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="http://www.jianshu.com/u/d9c480744afd" target="_blank" title="简书">
                    
                      <i class="fa fa-fw fa-globe"></i>简书</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="http://blog.csdn.net/kangvcar" target="_blank" title="CSDN">
                    
                      <i class="fa fa-fw fa-globe"></i>CSDN</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="https://my.oschina.net/kangvcar/blog" target="_blank" title="OSChina">
                    
                      <i class="fa fa-fw fa-globe"></i>OSChina</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="mailto:kangvcar@126.com" target="_blank" title="E-Mail">
                    
                      <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                </span>
              
            
          </div>

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Face-Recognition人脸识别库"><span class="nav-number">1.</span> <span class="nav-text">Face Recognition人脸识别库</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#特征"><span class="nav-number">1.1.</span> <span class="nav-text">特征</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#在图片中识别人脸"><span class="nav-number">1.1.1.</span> <span class="nav-text">在图片中识别人脸</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#找到并操作图片中的脸部特征"><span class="nav-number">1.1.2.</span> <span class="nav-text">找到并操作图片中的脸部特征</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#鉴定图片中的脸"><span class="nav-number">1.1.3.</span> <span class="nav-text">鉴定图片中的脸</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装"><span class="nav-number">1.2.</span> <span class="nav-text">安装</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#环境要求"><span class="nav-number">1.2.1.</span> <span class="nav-text">环境要求:</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#安装步骤"><span class="nav-number">1.2.2.</span> <span class="nav-text">安装步骤</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#在Mac或Linux上安装"><span class="nav-number">1.2.2.1.</span> <span class="nav-text">在Mac或Linux上安装</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#在树莓派2-上安装"><span class="nav-number">1.2.2.2.</span> <span class="nav-text">在树莓派2+上安装</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#在Windows上安装"><span class="nav-number">1.2.2.3.</span> <span class="nav-text">在Windows上安装</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#使用已经配置好的虚拟机（支持VMWare和VirtualBox）"><span class="nav-number">1.2.2.4.</span> <span class="nav-text">使用已经配置好的虚拟机（支持VMWare和VirtualBox）</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#使用方法"><span class="nav-number">1.3.</span> <span class="nav-text">使用方法</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#命令行界面"><span class="nav-number">1.3.1.</span> <span class="nav-text">命令行界面</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#调整公差-灵敏度"><span class="nav-number">1.3.2.</span> <span class="nav-text">调整公差/灵敏度</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#更多例子"><span class="nav-number">1.3.3.</span> <span class="nav-text">更多例子</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#加快人脸识别"><span class="nav-number">1.3.4.</span> <span class="nav-text">加快人脸识别</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Python模块"><span class="nav-number">1.3.5.</span> <span class="nav-text">Python模块</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#自动找到图片中所有的脸"><span class="nav-number">1.3.6.</span> <span class="nav-text">自动找到图片中所有的脸</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#自动识别人脸特征"><span class="nav-number">1.3.7.</span> <span class="nav-text">自动识别人脸特征</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#识别人脸鉴定是哪个人"><span class="nav-number">1.3.8.</span> <span class="nav-text">识别人脸鉴定是哪个人</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Python代码示例"><span class="nav-number">1.4.</span> <span class="nav-text">Python代码示例</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#人脸检测"><span class="nav-number">1.4.1.</span> <span class="nav-text">人脸检测</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#面部特征"><span class="nav-number">1.4.2.</span> <span class="nav-text">面部特征</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#面部识别"><span class="nav-number">1.4.3.</span> <span class="nav-text">面部识别</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#人脸识别如何运作"><span class="nav-number">1.4.4.</span> <span class="nav-text">人脸识别如何运作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#注意事项"><span class="nav-number">1.4.5.</span> <span class="nav-text">注意事项</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#部署到云端主机（Heroku，AWS等）"><span class="nav-number">1.4.6.</span> <span class="nav-text">部署到云端主机（Heroku，AWS等）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#常见问题"><span class="nav-number">1.4.7.</span> <span class="nav-text">常见问题</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#谢谢"><span class="nav-number">1.4.8.</span> <span class="nav-text">谢谢</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Kangvcar</span>

  
</div>


<div class="powered-by">
<i class="fa fa-user-md"></i><span id="busuanzi_container_site_pv">
    本站访客数:<span id="busuanzi_value_site_pv"></span>次
</span>
</div>








  <span class="post-meta-divider">|</span>




<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共32.7k字</span>
</div>
        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.3"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.3"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.3"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.3"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.3"></script>



  


  

    
      <script id="dsq-count-scr" src="https://kangvcar.disqus.com/count.js" async></script>
    

    
      <script type="text/javascript">
        var disqus_config = function () {
          this.page.url = 'http://www.kangvcar.com/face-recognition中文文档-第1节-人脸识别/';
          this.page.identifier = 'face-recognition中文文档-第1节-人脸识别/';
          this.page.title = '[face_recognition中文文档] 第1节 人脸识别';
        };
        var d = document, s = d.createElement('script');
        s.src = 'https://kangvcar.disqus.com/embed.js';
        s.setAttribute('data-timestamp', '' + +new Date());
        (d.head || d.body).appendChild(s);
      </script>
    

  




	





  












<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="//unpkg.com/valine/dist/Valine.min.js"></script>



  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  



  
    <script type="text/javascript" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>
  
  
<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/love.js"></script>

</body>
</html>
